package com.dlc.shop.systemtest.api.order;

import com.alibaba.fastjson.JSON;
import com.dlc.shop.bean.app.dto.MyOrderDto;
import com.dlc.shop.bean.model.Station;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;
import com.dlc.shop.systemtest.util.UrlEnum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @author Tu
 */
public class StationApi {
    public static List<Station> getStationList(Long shopId){
        String url = Constant.API_URL+"/p/station/userstation?current=1&size=1&lat=22.943953938872706&lng=113.39070900424778&stationName=&shopId="+shopId;
        List list = HttpUtil.get(url,List.class);
        HashMap hashMap = JSON.parseObject(JSON.toJSONString(list.get(0)), HashMap.class);
        List records = JSON.parseObject(JSON.toJSONString(hashMap.get("records")), List.class);
        if(0 == records.size()){
            return new ArrayList<>();
        }
        Station station = JSON.parseObject(JSON.toJSONString(records.get(0)), Station.class);
        return Arrays.asList(station);
    }

    /**
     * 在门店端查询订单信息
     * */
    public static MyOrderDto getStationOrderByCode(String code){
        String url = Constant.API_URL+"/p/station/getStationOrderByCode?code="+code;
        return HttpUtil.get(url,MyOrderDto.class, UrlEnum.STATION);
    }

    /**
     * 在门店端核销自提订单
     * */
    public static void orderStationByOrderNumber(String orderNumbers) {
        String url = Constant.API_URL + "/p/station/orderStationByOrderNumber";
        HttpUtil.put(url, orderNumbers, UrlEnum.STATION);
    }
    /**
     * 在门店端核销虚拟商品订单
     * */
    public static void  orderWriteOffByOrderNumber(MyOrderDto myOrderDto){
        String url = Constant.API_URL + "/p/station/orderWriteOffByOrderNumber";
        HttpUtil.put(url, myOrderDto, UrlEnum.STATION);
    }
}
